package com.buba.livenuniappservernew.common;

import io.swagger.annotations.ApiModelProperty;

/**
 * @author : pzg
 * @description : 公共返回类
 * @date : 2023/8/12 15:52
 */
public class CommonResult<T> {
    @ApiModelProperty(value = "返回码")
    private String code;
    @ApiModelProperty(value = "描述")
    private String desc;
    @ApiModelProperty(value = "返回数据")
    private T data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public CommonResult() {
    }

    public CommonResult(T data) {
        this.data = data;
    }

    public static CommonResult success() {
        CommonResult result = new CommonResult<>();
        result.setCode("200");
        result.setDesc("成功");
        return result;
    }

    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> result = new CommonResult<>(data);
        result.setCode("200");
        result.setDesc("成功");
        return result;
    }

    public static <T> CommonResult<T> success(String code, T data) {
        CommonResult<T> result = new CommonResult<>(data);
        result.setCode(code);
        result.setDesc("成功");
        return result;
    }

    public static <T> CommonResult<T> success(String code, T data, String desc) {
        CommonResult<T> result = new CommonResult<>(data);
        result.setCode(code);
        result.setDesc(desc);
        return result;
    }

    public static <T> CommonResult<T> success(Integer code, T data, String desc) {
        CommonResult<T> result = new CommonResult<>(data);
        result.setCode(code.toString());
        result.setDesc(desc);
        return result;
    }

    public static CommonResult error(String msg) {
        CommonResult result = new CommonResult();
        result.setCode("500");
        result.setDesc(msg);
        return result;
    }

    public static CommonResult error(String code, String msg) {
        CommonResult result = new CommonResult();
        result.setCode(code);
        result.setDesc(msg);
        return result;
    }

    public static CommonResult error(Integer code, String msg) {
        CommonResult result = new CommonResult();
        result.setCode(code.toString());
        result.setDesc(msg);
        return result;
    }

}
